#include "gnode.h"

GNode::GNode()
{
	isWrited=false;
	isDefinitionWrited=false;
}

vector<GNode*> GNode::parent()
{
	return parents;
}

int GNode::childCount()
{
	return children.size();
}

GNode* GNode::child( int index )
{
	if(index<0 || index>=children.size())
		return nullptr;
	else
		return children[index];
}

vector<GNode*> GNode::getChildren()
{
	return children;
}

void GNode::addChild( GNode* child )
{
	if (child->text.compare(this->text))
	{
		child->addParent(this);
		children.push_back(child);
	}
}

void GNode::addParent( GNode* node )
{
	if (!CheckParent(node))
		parents.push_back(node);
}

bool GNode::CheckParent( GNode* parent )
{
	for (int i=0;i<parents.size();++i)
	{
		if(parents[i]==parent)
			return true;
	}
	return false;
}

GNode::~GNode()
{
}

